<?php
namespace Admin\Controller;
use Lib\Controller\BaseController;

class UserController extends BaseController {

    private $userModel;
    private $SuggestModel;

    public function __construct(){
        $this->userModel = D('User');
        $this->SuggestModel = D('UserSuggest');
        parent::__construct();
    }

    /**
     * [user_list 用户列表]
     * @author xiezy
     * @date   2017-11-13
     * @return [type]     [description]
     */
    public function user_list() {
        $where = null;
        if (IS_POST) {
            switch(I('post.order_find')){
                case 1 :
                    $condition = 'user_name';
                    break;
                case 2 :
                    $condition = 'phone';
                default:
                    break;
            }
            $orderNo = I('post.keywords',null,'string');
            if($condition=='user_name'){
                if (trim($orderNo) != null) {
                    $where['u.user_name'] = array('like','%'.$orderNo.'%');
                }
            }
            else if($condition=='phone'){
                $where['u.phone'] = array('like','%'.$orderNo.'%');
            }

        }

        //获取订单数量
        $ordersNum = $this->userModel->getUserCount($where);
        //分页
        $p     = I('get.p',1);
        $page  = new \Lib\ORG\Page($ordersNum);
        $limit = $page->listRows;
        $pageString  = $p.','. $limit;
        $userList = $this->userModel->getUserList($page,$where,$pageString);
        // p($userList);die;
        //输出
        if ($userList) {
            $this->assign('userList', $userList );
        }

        $this->assign('page', $page->show());
        $this->assign('ordersNum', $ordersNum);
        $this->display();
    }

    /**
     * [user_single 單次服務的用戶]
     * @author xiezy
     * @date   2017-11-13
     * @return [type]     [description]
     */
    public function user_single(){
        $where = null;
        if (IS_POST) {
            switch(I('post.order_find')){
                case 1 :
                    $condition = 'user_name';
                    break;
                case 2 :
                    $condition = 'phone';
                default:
                    break;
            }
            $orderNo = I('post.keywords',null,'string');
            if($condition=='user_name'){
                if (trim($orderNo) != null) {
                    $where['u.user_name'] = array('like','%'.$orderNo.'%');
                }
            }
            else if($condition=='phone'){
                $where['u.phone'] = array('like','%'.$orderNo.'%');
            }

        }
        //单次卡用户
        $where['o.card_type'] = array('elt',1);
        // $where['o.card_type'] = array('gt',1);

        //获取订单数量
        $ordersNum = $this->userModel->getUserServerCount($where);
        //分页
        $p     = I('get.p',1);
        $page  = new \Lib\ORG\Page($ordersNum);
        $limit = $page->listRows;
        $pageString  = $p.','. $limit;
        $userList = $this->userModel->getUserServerList($page,$where,$pageString);

        //输出
        if ($userList) {
            $this->assign('userList', $userList );
        }

        $this->assign('page', $page->show());
        $this->assign('ordersNum', $ordersNum);
        $this->display();
    }

    /**
     * [user_single 單次服務的用戶]
     * @author xiezy
     * @date   2017-11-13
     * @return [type]     [description]
     */
    public function user_month(){
         $where = null;
        if (IS_POST) {
            switch(I('post.order_find')){
                case 1 :
                    $condition = 'user_name';
                    break;
                case 2 :
                    $condition = 'phone';
                default:
                    break;
            }
            $orderNo = I('post.keywords',null,'string');
            if($condition=='user_name'){
                if (trim($orderNo) != null) {
                    $where['u.user_name'] = array('like','%'.$orderNo.'%');
                }
            }
            else if($condition=='phone'){
                $where['u.phone'] = array('like','%'.$orderNo.'%');
            }

        }

        // $where['o.card_type'] = array('elt',1); //单次卡用户
        // $where['o.card_type'] = array('gt',1);   //月卡

        //获取订单数量
        $ordersNum = $this->userModel->getUserMonthCount($where);
        //分页
        $p     = I('get.p',1);
        $page  = new \Lib\ORG\Page($ordersNum);
        $limit = $page->listRows;
        $pageString  = $p.','. $limit;
        $userList = $this->userModel->getUserMonthList($page,$where,$pageString);

        //输出
        if ($userList) {
            $this->assign('userList', $userList );
        }

        $this->assign('page', $page->show());
        $this->assign('ordersNum', $ordersNum);
        $this->display();
    }

    /**
     * [view_suggest 查看用户建议]
     * @author xiezy
     * @date   2017-11-13
     * @return [type]     [description]
     */
    public function view_suggest() {
        $where = null;
        if (IS_POST) {
            switch(I('post.order_find')){
                case 1 :
                    $condition = 'user_name';
                    break;
                case 2 :
                    $condition = 'contact';
                    break;
                case 3 :
                    $condition = 'contact_phone';
                default:
                    break;
            }
            $orderNo = I('post.keywords',null,'string');
            if($condition=='contact'){
                if (trim($orderNo) != null) {
                    $where['us.contact'] = array('like','%'.$orderNo.'%');
                }
            }
            else if($condition=='contact_phone'){
                $where['us.contact_phone'] = array('like','%'.$orderNo.'%');
            }
            else if($condition=='user_name'){
                $where['u.user_name'] = array('like','%'.$orderNo.'%');
            }

        }
        // p($this->SuggestModel);die;
        //获取订单数量
        $ordersNum = $this->SuggestModel->getUserCount($where);
        //分页
        $p     = I('get.p',1);
        $page  = new \Lib\ORG\Page($ordersNum);
        $limit = $page->listRows;
        $pageString  = $p.','. $limit;
        $suggestList = $this->SuggestModel->getUserList($page,$where,$pageString);

        //输出
        if ($suggestList) {
            $this->assign('suggestList', $suggestList );
        }

        $this->assign('page', $page->show());
        $this->assign('ordersNum', $ordersNum);
        $this->display();

    }


}

?>
